import { productListPage,productCreate,productDelete,productUpdate,productRemoves} from "@/api/product"

const user = {
  state: {
    data:{}
  },

  mutations: {
    ProductList:(state,data)=>{
      state.data=data;
    }
    // productCreate:(state,data)=>{
    //   state.data = data;
    // },
    // productDelete:(state,data)=>{
    //   state.data = data;
    // },
    // productUpdate:(state,data)=>{
    //   state.data = data;
    // }
  },

  actions: {
    //创建新产品数据
    productCreate({commit}){
      return new Promise((resolve,reject)=>{
        productCreate().then(response=>{
          console.log(response);
          commit("ProductCreate",response);
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    },
    // 有页码约束的所有产品数据
    productList({commit},playload) {
      return new Promise((resolve, reject) => {
        productListPage(playload).then(response => {
          console.log(response);
          commit("ProductList",response);
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    //删除单个产品数据
    productDelete({commit},id){
      return new Promise((resolve,reject)=>{
        productDelete(id).then(response=>{
          commit("ProductDelete",response);
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    },
    //修改
    productUpdate({commit},id){
      return new Promise((resolve,reject)=>{
        productUpdate(id).then(response=>{
          commit("ProductUpdate",response);
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    },
    //删除多个产品数据
    productRemoves({commit},selectionArray){
      return new Promise((resolve,reject)=>{
        productRemoves(selectionArray).then(response=>{
          commit("UserRemoves",response)
          resolve(response)
        }).catch(error=>{
          reject(error)
        })
      })
    }
  }
}

export default user;
